package cn.hwadee.muying.service;

import cn.hwadee.muying.entity.ReturnVisit;
import cn.hwadee.muying.mapper.ReturnVisitMapper;
import cn.hwadee.muying.commons.base.BaseService;
import org.springframework.stereotype.Service;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.commons.page.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 回访记录 服务实现类
 * </p>
 *
 * @author Mankind
 * @since 2018-08-06
 */
@Service
public class ReturnVisitService extends BaseService<ReturnVisitMapper, ReturnVisit> {

    @Autowired
    private ReturnVisitMapper returnVisitMapper;
    @Autowired
    private UserService userService;

    public MyPage<ReturnVisit> list(MyPage<ReturnVisit> page, User cUser) throws Exception{
        List<ReturnVisit> returnVisits = returnVisitMapper.list(page,cUser);
        for(ReturnVisit returnVisit:returnVisits){
            if(returnVisit.getTargetId()!=null){
                User user=userService.selectById(returnVisit.getTargetId());
                returnVisit.setUsername(user.getUsername());
            }
        }
        page.setRecords(returnVisits);
        return page;
    }

}
